package main

import (
	"fmt"
	"strings"
	"unicode"
)

/*
@author: wy
@file: passwdauth.py
@time: 2023/11/25 11:10
*/
func main() {
	var ptr *int
	score := 2
	ptr = &score
	var passwd string
	println("请输入你的密码:")
	fmt.Scanln(&passwd)
	println(passwdauth(ptr, passwd))
}
func passwdauth(score *int, password string) (int, string) {
	var str1 string
	flag1 := 0
	flag2 := 0
	flag3 := 0
	flag4 := 0
	//1
	if len(password) >= 8 {
		*score += 1
	} else {
		str1 = str1 + "\t密码不足八位！\t"
	}
	//2
	for _, j := range password {
		if unicode.IsDigit(j) {
			flag1 = 1
		}
		if unicode.IsLower(j) {
			flag2 = 1
		}
		if unicode.IsUpper(j) {
			flag3 = 1
		} else {
			flag4 = 1
		}
	}
	if flag4+flag1+flag2+flag3 >= 3 {
		*score += 1
	} else {
		str1 = str1 + "密码没有由三种以上字符组成!\t"
	}
	//3
	count := 1
	for i := 0; i < len(password); i++ {
		for j := 3; j < len(password); j++ {
			count = strings.Count(password, password[i:j])
			if count >= 2 {
				str1 = str1 + "密码有超过或等于3的字串重复!\t"
				break
			}
		}
		if count >= 2 {
			break
		}
	}
	if count == 1 {
		*score += 1
	}
	return *score, str1
}
